<!DOCTYPE HTML>
<html lang="zh-cn" ng-app="MainApp">
<head>
    <meta charset="UTF-8">
    <title>services</title>
</head>
<body>
<div ng-controller="MyController">
    <input type="text" ng-model="msg"/>
    <button ng-click="saveMsg()">save msg</button>
    <ul>
        <li ng-repeat="msg in msgs">{{msg}}</li>
    </ul>
</div>

<div ng-controller="MyController1">
    <input type="text" ng-model="msg"/>
    <button ng-click="saveMsg()">save msg</button>
    <ul>
        <li ng-repeat="msg in msgs">{{msg}}</li>
    </ul>
</div>
<script src="../angular-1.0.1.js" type="text/javascript"></script>
<script type="text/javascript">
    var app = angular.module("MainApp",[],function($provide) {
        $provide.factory("notify",["$window","$timeout",function(win,timeout) {
            var msgs = [];
            return function(msg) {
                msgs.push(msg);
                if(msgs.length==3) {
                    timeout(function() {
                        win.alert(msgs.join("\n"));
                        msgs = [];
                    },10);
                }
            }
        }])
    });
    app.controller("MyController",function($scope,notify,factory1,servic1) {
        $scope.msgs = [];
        $scope.saveMsg  = function() {
            factory1.name = 223;
            servic1.name = 223;
            this.msgs.push(this.msg);
            notify(this.msg);
            this.msg = "";
        };
    });
    app.controller("MyController1",function($scope,notify,factory1,servic1) {
        $scope.msgs = [];
        $scope.saveMsg  = function() {
           let ssfds= factory1.name;
           let fff= servic1.name;
            this.msgs.push(this.msg);
            notify(this.msg);
            this.msg = "";
        };
    });
    app.factory("factory1",function(){
        return {
            name:"123"
        }
    })
    app.service("servic1",function(){
        let service={};
        service.name="123";
        return service;
    })
</script>
</body>
</html>